<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>scope destory</title>
</head>
<body>
    
    <script>
    
        {
            // scope destory
            // 销不销毁 看外部是否引用  形成闭包

            function fn () {
                var sum = 10;
                return function () {
                    return sum = sum + 10;
                }
            }

            console.log(fn()()); 
            console.log(fn()());
            console.log(fn()());


        }

        {

            // 自执行函数不销毁
            var n = 10;
            (function (n) {
                
                

            })(n);

        }

        {
            function fn () {
                var num = 100;
                return function () {
                    return num = num + 100;
                }
            }

            let f = fn();


            console.log(fn()());
            console.log(fn()());
            console.log(fn()());

            console.log(f());
            console.log(f());
            console.log(f());
        }
    
    </script>

</body>
</html>